﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObject;
using System.Data;
using Entity;

namespace GreenLife.Admin
{
    public partial class DanhSachDanhMucCon : System.Web.UI.Page
    {
        SubCategoriesBO scBO = new SubCategoriesBO();
        CategoriesBO cBO = new CategoriesBO();
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                selectCate();
                Bind_ddlState();
            }
        }

        private void selectCate()
        {
            ddlTower.Items.Add("Tower A");
            ddlTower.Items.Add("Tower B");
        }
        private void Bind_ddlState()
        {
            ds = cBO.selectCategoryByType(ddlTower.SelectedValue.ToString());
            ddlCate.DataSource = ds.Tables[0];
            ddlCate.Items.Clear();
            ddlCate.DataTextField = "CategoryName";
            ddlCate.DataValueField = "CategoryID";
            ddlCate.DataBind();
        }
        protected void ddlTower_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bind_ddlState();
            selectSubCategory(Int32.Parse(ddlCate.SelectedValue.ToString()));
        }
        protected void ddlCate_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectSubCategory(Int32.Parse(ddlCate.SelectedValue.ToString()));
        }

        public void selectSubCategory(int id)
        {
            ds = scBO.getSubCategoryByCate(id);
            this.listSubCategory.DataSource = ds.Tables[0];
            this.listSubCategory.DataBind();
            //CollectionPager1.PageSize = 5;//thay doi so ban tin hien thi
            //CollectionPager1.DataSource = ds.Tables[0].DefaultView;
            //CollectionPager1.BindToControl = listSubCategory;
            //listSubCategory.DataSource = CollectionPager1.DataSourcePaged;
        }

        protected void cpRepeaterSubCategory_ItemDataBound(object sender, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                int sno = Int32.Parse(e.CommandArgument.ToString());
                SubCategory sc = new SubCategory();
                sc.SubCategory_ID = sno;
                scBO.removeSubCategory(sc);
                selectSubCategory(Int32.Parse(ddlCate.SelectedValue.ToString()));
            }
        }

    }
}